package com.yida.gwj.expend.outside.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.yida.common.core.exception.ServiceException;
import com.yida.gwj.common.enums.GwjBusinessFlagType;
import com.yida.gwj.expend.outside.domain.GwjMaintenanceFundsBusinessAttachment;
import com.yida.gwj.expend.outside.domain.dto.AllocatedAmountSelectDTO;
import com.yida.gwj.expend.outside.domain.dto.ChangeSchemeDTO;
import com.yida.gwj.expend.outside.domain.request.AllocatedAmountRequest;
import com.yida.gwj.expend.outside.enums.BusinessAttachmentServerTypeEnum;
import com.yida.gwj.expend.outside.service.GwjConfNoticeService;
import com.yida.gwj.expend.outside.service.IGwjMaintenanceFundsBusinessAttachmentService;
import com.yida.gwj.expend.outside.service.IGwjMaintenanceFundsBusinessService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description 公维金信息公示
 * @Author wws
 * @Date 2023-06-21
 */
@Service
public class GwjConfNoticeServiceImpl implements GwjConfNoticeService {

    @Resource
    private IGwjMaintenanceFundsBusinessAttachmentService gwjMaintenanceFundsBusinessAttachmentService;

    @Resource
    private IGwjMaintenanceFundsBusinessService gwjMaintenanceFundsBusinessService;

    /**
     * 附件列表查询
     * @param gwjMaintenanceFundsBusinessAttachment
     * @return
     */
    @Override
    public List<GwjMaintenanceFundsBusinessAttachment> selectMaintenanceFundsBusinessAttachment(GwjMaintenanceFundsBusinessAttachment gwjMaintenanceFundsBusinessAttachment) {
        if(StrUtil.isBlank(gwjMaintenanceFundsBusinessAttachment.getServerIdentification())){
            throw new ServiceException("文件业务标识不能为空");
        }
        List<GwjMaintenanceFundsBusinessAttachment> list = gwjMaintenanceFundsBusinessAttachmentService.selectGwjMaintenanceFundsBusinessAttachmentList(gwjMaintenanceFundsBusinessAttachment);
        list = list.stream().filter(item -> item.getType().equals(BusinessAttachmentServerTypeEnum.PROJECT_BUDGET.getCode())
        || item.getType().equals(BusinessAttachmentServerTypeEnum.TRANSFORMATION_PLAN.getCode())).collect(Collectors.toList());
        return list;
    }

    /**
     * 查询维修和更新、改造方案
     * @param bizId 业务主键
     * @return
     */
    @Override
    public ChangeSchemeDTO getTransformationPlan(Long bizId) {
        return gwjMaintenanceFundsBusinessService.getTransformationPlan(bizId);
    }

    /**
     * 分摊金额列表
     * @param allocatedAmountRequest
     * @return
     */
    @Override
    public AllocatedAmountSelectDTO allocatedAmountList(AllocatedAmountRequest allocatedAmountRequest) {
        return gwjMaintenanceFundsBusinessService.allocatedAmountList(allocatedAmountRequest, GwjBusinessFlagType.EXPEND_OUTSIDE);
    }
}
